import 'package:Smart/pages/productor007/studytest/flutter_boss/model/company.dart';
import 'package:Smart/pages/productor007/studytest/flutter_boss/view/company/company_hot_job.dart';
import 'package:Smart/pages/productor007/studytest/flutter_boss/view/company/company_inc.dart';
import 'package:Smart/pages/productor007/studytest/flutter_boss/view/company/company_info.dart';
import 'package:Smart/pages/productor007/studytest/flutter_boss/view/company/company_swiper.dart';
import 'package:flutter/material.dart';
// import 'package:flutter_boss/model/company.dart';
// import 'package:flutter_boss/view/company/company_hot_job.dart';
// import 'package:flutter_boss/view/company/company_inc.dart';
// import 'package:flutter_boss/view/company/company_info.dart';
// import 'package:flutter_boss/view/company/company_swiper.dart';
const double _kAppBarHeight = 256.0;

class CompanyDetail extends StatefulWidget {
  final Company _company;

  CompanyDetail(this._company);

  @override
  _CompanyDetailState createState() => _CompanyDetailState();
}

class _CompanyDetailState extends State<CompanyDetail>
    with TickerProviderStateMixin {

  List<Tab> _tabs;
  List<Widget> _imagePages;
  TabController _controller;
  List<String> _urls = [
    'https://img1.baidu.com/it/u=2336137416,3593454803&fm=26&fmt=auto&gp=0.jpg',
    'https://img1.baidu.com/it/u=251674983,1047412732&fm=26&fmt=auto&gp=0.jpg',
    'https://img1.baidu.com/it/u=1020384080,2889778571&fm=26&fmt=auto&gp=0.jpg'
  ];

  Widget _companyTabContent;
  VoidCallback onChanged;
  int _currentIndex = 0;

  @override
  void initState() {
    super.initState();
    //print(widget._company.images[0]);

    // if (!_urls.isEmpty) {
    //   _imagePages = [];
    //   _urls.forEach((String url) {
    //     _imagePages.add(
    //       Container(
    //         color: Colors.black.withAlpha(900),
    //         child: ConstrainedBox(
    //           constraints: BoxConstraints.expand(),
    //           child: Image.network(
    //             url,
    //             fit: BoxFit.cover,
    //             height: _kAppBarHeight,
    //           ),
    //         )
    //       ) 
    //     );
    //   });
    // }

     _tabs = [
    Tab(text:'公司概况'),
    Tab(text:'热招职位')
  ];

 _companyTabContent = CompanyInc(widget._company.inc);
  _controller = TabController(length: _tabs.length,vsync: this);
  onChanged = (){
    setState(() {
      if(_currentIndex == 0){
        _companyTabContent = CompanyInc(widget._company.inc);
      }else{
        _companyTabContent = CompanyHotJob();
      }

      _currentIndex = this._controller.index;
    });
  };

  _controller.addListener(onChanged);


  }
  @override
  void dispose() {
    _controller.removeListener(onChanged);
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
   
    return Scaffold(
      backgroundColor:Color.fromARGB(255, 242, 242, 245) ,
      body: Stack(
        children: [
          SingleChildScrollView(
            child: Column(
              children: [
                  //轮播图部分
                  SizedBox.fromSize(
                    size: Size.fromHeight(_kAppBarHeight),
                    child: SwiperExample(widget._company.images),
                  ),

                  Container(
                    color: Colors.white,
                    child: Column(
                      children: [
                        //公司信息
                        CompanyInfo(widget._company),
                        Divider(),
                        //tab栏
                        TabBar(
                          indicatorWeight: 3.0, 
                          indicatorSize: TabBarIndicatorSize.tab,
                          labelStyle: TextStyle(fontSize: 16.0),
                          controller: _controller,
                          tabs:_tabs,
                          indicatorColor: Theme.of(context).primaryColor,
                        )
                      ],
                    ),
                  ),

                  //tab栏里面的内容
                  _companyTabContent,

                  // Container(
                  //   height:400 ,
                  //   color: Colors.cyan,
                  //   child: Text("SingleChildScrollView"),
                  // )

              ],
            ),


          ),

          Positioned(
            top: 10.0,
            left: -10.0,
            child:Container(
              padding: EdgeInsets.all((15.0)),
              child:BackButton(color: Colors.white,),
            ),
          )
        ],
      ),
    );
  }


 
  
}
